import { createSelector } from '@ngrx/store';

import { MapState } from '../reducers';
import { getMapState } from './map.selector';
import { BasemapState } from '../reducers';
import { Basemap } from '../../models';

const getBasemapsState = createSelector(getMapState, (state: MapState) => state.basemaps);
const getBasemapsEntities = createSelector(getBasemapsState, (state: BasemapState) => state.entities);
const getAllBasemaps = createSelector(getBasemapsEntities, (entities: { [id: string]: Basemap }) => {
    return Object.keys(entities).map((key: string) => {
        return entities[key];
    });
});
const getCheckedBasemaps = createSelector(getBasemapsState, (state: BasemapState) => state.entities[state.checked]);

export const basemapsSelector = {
    getBasemapsState,
    getBasemapsEntities,
    getAllBasemaps,
    getCheckedBasemaps
};